package org.jeecg.modules.param.spend.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.param.member.entity.BikeMemberUser;
import org.jeecg.modules.param.spend.entity.BikeMemberUserSpend;
import org.jeecg.modules.param.spend.mapper.BikeMemberUserSpendMapper;
import org.jeecg.modules.param.spend.service.IBikeMemberUserSpendService;
import org.jeecg.modules.utils.CostUtils;
import org.jeecg.modules.utils.ExcelUtils;
import org.jeecg.modules.utils.page.PageInfo;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Comparator;
import java.util.List;

/**
 * @Description: 消费记录
 * @Author: 月月鸟
 * @Date:   2021-05-31
 * @Version: V1.0
 */
@Service
public class BikeMemberUserSpendServiceImpl extends ServiceImpl<BikeMemberUserSpendMapper, BikeMemberUserSpend> implements IBikeMemberUserSpendService {
    @Resource
    private BikeMemberUserSpendMapper bikeMemberUserSpendMapper;
    @Override
    public Result<?> pageList(Integer pageNo, Integer pageSize, BikeMemberUserSpend bikeMemberUserSpend) {
        Page<BikeMemberUserSpend> page = new Page<>(pageNo, pageSize);
        Page<BikeMemberUserSpend> bikeMemberUserSpends = bikeMemberUserSpendMapper.pageList(page,bikeMemberUserSpend);
        if (bikeMemberUserSpend!=null){
            List<BikeMemberUserSpend> records = bikeMemberUserSpends.getRecords();
            for (BikeMemberUserSpend tb :records){
                if (tb.getUseLong()!=null){
                    tb.setUseMMss(CostUtils.MMss(tb.getUseLong()));
                }
            }
        }
        PageInfo pageInfo = new PageInfo();
        pageInfo.setSize(bikeMemberUserSpends.getSize());
        pageInfo.setCurrent(bikeMemberUserSpends.getCurrent());
        pageInfo.setRecords(bikeMemberUserSpends.getRecords());
        pageInfo.setTotal(bikeMemberUserSpends.getTotal());
        return Result.OK(pageInfo);
    }

    @Override
    public ModelAndView exportXls(HttpServletRequest request, BikeMemberUserSpend bikeMemberUserSpend, Class<BikeMemberUserSpend> bikeMemberUserSpendClass, String title) {
        List<BikeMemberUserSpend> bikeMemberUserSpends = bikeMemberUserSpendMapper.list(bikeMemberUserSpend);
        for (BikeMemberUserSpend tb :bikeMemberUserSpends){
            if (tb.getUseLong()!=null){
                tb.setUseMMss(CostUtils.MMss(tb.getUseLong()));
            }
        }
        return ExcelUtils.exportXls(request,bikeMemberUserSpends,BikeMemberUserSpend.class,title);
    }
}
